import draggable from 'dd-form-draggable'

import ElementPlus from 'element-plus'

import zhCn from 'element-plus/es/locale/lang/zh-cn'
import Cookies from 'js-cookie'
import { createApp } from 'vue'

import VFormDesigner from '@/assets/draggable/dist/designer.es'

import DictTag from '@/components/DictTag/index.vue'
import Editor from '@/components/Editor/index.vue'
import FileUpload from '@/components/FileUpload/index.vue'
import ImagePreview from '@/components/ImagePreview/index.vue'

import ImageUpload from '@/components/ImageUpload/index.vue'
import Pagination from '@/components/Pagination/index.vue'
import RightToolbar from '@/components/RightToolbar/index.vue'

import SvgIcon from '@/components/SvgIcon/index.vue'
import elementIcons from '@/components/SvgIcon/svgicon'

import TreeSelect from '@/components/TreeSelect/index.vue'
import { useDict } from '@/utils/dict'
import { download } from '@/utils/request'

import { addDateRange, handleTree, parseTime, resetForm, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'

import submitNoEnter from '@/utils/submitNoEnter'

import App from './App.vue'
import directive from './directive'

import plugins from './plugins'
import router from './router'
import store from './store'
import 'element-plus/theme-chalk/index.css'
import '@/assets/styles/index.scss'
import '@/assets/draggable/dist/designer.style.css'
import 'virtual:svg-icons-register'
import './permission'

const app = createApp(App)

// 全局方法挂载
app.config.globalProperties.useDict = useDict
app.config.globalProperties.download = download
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels

// 全局组件挂载
app.component('DictTag', DictTag)
app.component('Pagination', Pagination)
app.component('TreeSelect', TreeSelect)
app.component('FileUpload', FileUpload)
app.component('ImageUpload', ImageUpload)
app.component('ImagePreview', ImagePreview)
app.component('RightToolbar', RightToolbar)
app.component('Editor', Editor)
app.component('draggable', draggable)

app.use(router)
app.use(store)
app.use(plugins)
app.use(elementIcons)
app.use(VFormDesigner)
app.component('svg-icon', SvgIcon)
app.mixin(submitNoEnter)
directive(app)

// 使用 element-plus 并设置全局大小 + 中文
app.use(ElementPlus, {
  locale: zhCn,
  size: Cookies.get('size') || 'default',
})

app.mount('#app')
